package com.marvels.approve.consum.impl;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.alibaba.fastjson.JSONObject;
import com.marvels.approve.consum.ApproveConsumerSystemApi;
import com.marvels.approve.loan.dto.McsmSystemParam;
import com.marvels.common.dto.MarvelsResultDTO;
import com.marvels.common.dto.UserDTO;
import com.marvels.common.exception.MarvelsErrorCode;
import com.marvels.common.utils.MarvelsLogUtil;
import com.marvels.system.common.api.SystemParamsApi;
import com.marvels.system.common.service.SysLoginService;

@Component
public class ApproveConsumSystemImpl implements ApproveConsumerSystemApi{

	@Autowired
	private SystemParamsApi systemParamsApi;
	
	@Autowired
	private SysLoginService sysLoginService;
	
	@Override
	public List<McsmSystemParam> paramList(McsmSystemParam mcsmSystemParam) {
		try {
			List<com.marvels.system.permission.dto.McsmSystemParam> apiResult = systemParamsApi.paramList(mcsmSystemParam.getParamNames());
			List<McsmSystemParam> result = JSONObject.parseArray(JSONObject.toJSONString(apiResult), McsmSystemParam.class);
			MarvelsLogUtil.getInstance().info("ApproveConsumerSystemApi.paramList direct call success!");
			return result;
		} catch (Exception e) {
			MarvelsLogUtil.getInstance().error("ApproveConsumerSystemApi.paramList error", e);
			return null;
		}
	}

	@Override
	public MarvelsResultDTO login(UserDTO user, HttpServletRequest request) {
		try {
			MarvelsResultDTO result = sysLoginService.login(user, request);
			MarvelsLogUtil.getInstance().info("ApproveConsumerSystemApi.login direct call success!");
			return result;
		} catch(Exception e){
			MarvelsLogUtil.getInstance().error("ApproveConsumerSystemApi.login error", e);
			return MarvelsResultDTO.getResult(MarvelsErrorCode.ERROR.getValue(), MarvelsErrorCode.ERROR.getDesc(), e);
		}
	}

}
